<?php
// +----------------------------------------------------------------------
// | UCToo [ Universal Convergence Technology ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2020 https://www.uctoo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Patrick <contact@uctoo.com>
// +----------------------------------------------------------------------
namespace app\admin\model\wechatopen;

use app\common\controller\Backend;
use think\Exception;
use think\Model;
use think\Request;
use app\admin\library\Auth;

class WechatopenModel extends Model
{
    /**
     * 是否开启数据限制
     * 支持wechatapplet_id
     * 表示以表的wechatapplet_id字段限制数据访问权限
     * 默认为禁用,若启用请务必保证表中存在wechatapplet_id字段
     */
    protected $dataLimit = false;
    protected $appconfig;

    /**
     * 数据限制字段
     */
    protected $dataLimitField = 'wechatapplet_id';

    protected function base($query)
    {
        if($this->dataLimit){
            $applet_info = session('applet_info');  //从上下文（已登录后台或被动消息接口）获取当前操作的应用信息

            if($applet_info['wechatapplet_id'] == null){
                trace('未选择应用');
            }

            $globalKey['wechatapplet_id'] = ['=' ,$applet_info['wechatapplet_id']];
            $query->where($globalKey);
        }
    }
}
